﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ThreeByte.ActiveDeck.Service
{
    public class BlockList
    {
        private static readonly XNamespace ns = ServiceConfiguration.NAMESPACE;

        public List<string> BlockIDs { get; private set; }
        //public string Name { get; private set; }
        //public string DataType { get; private set; }
        //public int Size { get; private set; }

        public BlockList(List<string> blockIds = null) {
            if(blockIds != null) {
                BlockIDs = blockIds;
            } else {
                BlockIDs = new List<string>();
            }
        }

        public void Add(string blockID) {
            BlockIDs.Add(blockID);
        }

        public XElement ToXml() {
            
            XElement node = new XElement(ns + "BlockList");
            //node.Add(new XAttribute("Name", Name ?? string.Empty));
            //node.Add(new XAttribute("Type", DataType ?? string.Empty));

            foreach(string id in BlockIDs){
                node.Add(new XElement(ns + "BlockID", id));
            }
            return node;
        }

        public static BlockList Parse(XElement node) {
            BlockList newBlockList = new BlockList();
            foreach(XElement id in node.Elements(ns + "BlockID")) {
                newBlockList.Add(id.Value);
            }

            return newBlockList;
        }
    }
}
